<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 
        promise如何串联多个操作任务
          1)promise的then()返回一个新的promise,可以开成then()的链式调用
          2)通过then的链式调用串联多个同步/异步任务

          
     -->
    <script>
        new Promise((resolve, reject) => {
            console.log('开启了第一次异步任务');
            setTimeout(() => {
                resolve('数据1')
            }, 1000)
        }).then(
            value => console.log('第1个异步任务成功了，值为:', value),
        ).then(
            value => {
                console.log('开启了第2个同步任务');
                let a = '数据2'
                console.log('第2个同步任务成功了，值为:', a);
                return a
            }
        ).then(
            value => {
                console.log('开启了第3个异步任务');
                return new Promise((resolve, reject) => {
                    setTimeout(() => {
                        let data = '数据3'
                        resolve(data)
                    }, 1000)
                })
            }
        ).then(
            value => console.log('第3个异步任务成功了，值为:', value),
        )


    </script>
</body>

</html>